package com.ilearn.iodata.iolingo.service.processor.core.database;

import com.ilearn.iodata.iolingo.service.processor.GenericODataDatabaseProcessor;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

/**
 * Created by lyndon on 2018/6/6.
 */
public class GenericODataDatabaseProcessorFactory {
    private static final String PRODUCT_NAME_H2 = "H2";
    private static final String PRODUCT_NAME_HSQLDB = "HSQL Database Engine";
    private static final String PRODUCT_NAME_SAP_HANA = "HDB";

    public GenericODataDatabaseProcessor create(final DataSource ds) throws SQLException {
        if (ds != null) {
            final Connection connection = ds.getConnection();
            final DatabaseMetaData dbMetadata = connection.getMetaData();
            connection.close();
            if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_SAP_HANA))
                return null;
            else if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_HSQLDB))
                return null;
            else if (dbMetadata.getDatabaseProductName().equals(PRODUCT_NAME_H2))
                return null;
            else
                return null;
        } else
            return null;
    }
}
